#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const int N = 1010, M = 200010;
int h[N], ne[M], e[M], w[M], idx;
bool st[N];
deque<int> q;
int dist[N];
int n, m, k;
void add(int a, int b, int c)
{
    e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
bool check(int bound)
{
    memset(st, false, sizeof st);
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;
    q.push_front(1);
    while (q.size())
    {
        int t = q.front();
        q.pop_front();
        if (st[t]) continue;
        st[t] = true;
        for (int i = h[t]; ~i; i = ne[i])
        {
            int j = e[i];
            int v = w[i] >= bound;
            if (dist[j] > dist[t] + v)
            {
                dist[j] = dist[t] + v;
                if (v == 0) q.push_front(j);
                else q.push_back(j);
            }
        }
    }
    return dist[n] > k;
}
int main()
{
    memset(h, -1, sizeof h);
    cin >> n >> m >> k;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        add(a, b, c), add(b, a, c);
    }
    int l = 0, r = 1e6 + 1;
    while (l < r)
    {
        int mid = l + r + 1 >> 1;
        if (check(mid)) l = mid;
        else r = mid - 1;
    }
    if (r == 1e6 + 1) cout << "-1" << endl;
    else cout << r << endl;
    return 0;
}